// pages/personal/myaddress/myaddress.js
const app = getApp();
var utils = require('../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
    },
	onShow: function () {
		var that = this;
		that.getAddressList();
	},
	getAddressList:function(e){
		var that=this;
		utils.http("/api/v1/address/address_list",{},function(res){
			that.setData({
				list: res.datas
			})
		})
	},
   

    //点击列表
    onChaneTap:function(e){
        app.globalData.addressChid = e.currentTarget.dataset.id
		app.globalData.addressChNum = 2
        wx.navigateBack({})
    },

    //跳入新增地址页面
	oneditAddresTap:function(e){
		//console.log(e.currentTarget.dataset.id)
        wx.navigateTo({
			url: '../addaddress/addaddress?id=' + e.currentTarget.dataset.id
        })
    },
	//删除地址信息
	delAddresTap:function(e){
		var that=this;
		utils.http("/api/v1/address/del_address",{
			address_id: e.currentTarget.dataset.id
		},function(res){
			utils.showSuccess('删除成功', 'none', false, 800);
			that.getAddressList();
		})
	},
	// //设置默认地址
	// radioChange:function(e){
	// 	var that=this;
	// 	http.post("address/set_default",{
	// 		id: e.currentTarget.dataset.id
	// 	},function(res){
	// 		console.log(res);
	// 		app.globalData.addressChid = undefined
	// 		that.getAddressList();
	// 	})
	// }

 
})